package cn.itsource.itsource.service.impl;

import cn.itsource.itsource.domain.Detail;
import cn.itsource.itsource.domain.LinYu;
import cn.itsource.itsource.mapper.DetailMapper;
import cn.itsource.itsource.query.DetailQuery;
import cn.itsource.itsource.service.IDetailService;
import cn.itsource.itsource.util.AjaxResult;
import cn.itsource.itsource.util.PageList;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class DetailServiceImpl implements IDetailService {

    @Autowired
    private DetailMapper detailMapper;

    @Override
    public AjaxResult pageListById(DetailQuery query) {
        PageHelper.startPage(query.getCurrPage(),query.getPageSize());
        PageInfo<Detail> pageInfo = new PageInfo<>(detailMapper.pageListById(query));

        PageList<Detail> pageList=new PageList(pageInfo.getTotal(),pageInfo.getList());
        AjaxResult result = AjaxResult.success("操作成功");
        result.setData(pageList);

        return  result;

    }

    @Override
    public AjaxResult saveOrUpdate(Detail detail) {
            detailMapper.save(detail);
        return AjaxResult.success("操作成功");
    }

    @Override
    public AjaxResult del(Long id) {

        detailMapper.del(id);

        return AjaxResult.success("删除成功");
    }
}
